package com.wondersgroup.fjzlpt.org.dao.impl.fwbFwxx;

import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Repository;

import com.alibaba.fastjson.JSONArray;
import com.quick.framework.boot.repository.sql.bean.SQLBean;
import com.quick.framework.boot.repository.sql.bean.table.TableBean;
import com.quick.framework.boot.repository.sql.jdbcTemplate.impl.BaseJTDAOImpl;
import com.wondersgroup.fjzlpt.org.dao.inter.fwbFwxx.FwbFwxxDAO;
@Repository
public class FwbFwxxDAOImpl extends BaseJTDAOImpl implements FwbFwxxDAO{
	@Override
	@Autowired
	@Qualifier("TB_XXWH_FWB_FWXX")
	public void setTb(TableBean tb) {
		super.setTb(tb);
	}

	@Override
	public boolean validate(Map<String, String> map) {
		String fwid = map.get("FWID");
		StringBuffer sql =  new StringBuffer();
		sql.append("select count(1) from TB_XXWH_FWB_FWXX where FWID = ? ");
		SQLBean sb = new SQLBean(sql.toString(), new Object[]{fwid});
		return super.isExist(sb);
	}

	/**
	 * 删除服务包中所有服务
	 */
	@Override
	public void deleteByFwbId(Map<String, String> map) {
		String fwbid = (String)map.get("FWBID");
		StringBuffer sql =  new StringBuffer();
		sql.append("delete from TB_XXWH_FWB_FWXX where FWBID = ? ");
		SQLBean sb = new SQLBean(sql.toString(), new Object[]{fwbid});
		super.update(sb);
	}

	/**
	 * 查询服务包下的服务项
	 * @param FWBID
	 */
	public JSONArray queryFwxxsByFwbId(String FWBID) {
		StringBuilder sbud = new StringBuilder("select a.*,b.YLJGMC,c.XMMC FWLBMC,d.FWBID,d.FWPCLX,d.FWPC \n");
		sbud.append("from TB_XXWH_FWXX a, TB_ZD_YLJGXX b, TB_ZY_SERVICE_TYPE c,TB_XXWH_FWB_FWXX d \n");
		sbud.append(" where a.YLJGID = b.PTJGID  and a.FWLB = c.XMDM  and a.FWID = d.FWID and d.FWBID = ? \n");
		SQLBean sb = new SQLBean(sbud.toString(), new Object[]{FWBID});
		return super.queryList(sb);
	}

	
}
